import { Entity, Column, PrimaryGeneratedColumn, ManyToMany, JoinTable } from 'typeorm'

import { Book } from './book.entity'
@Entity({ name: 'tags' })
export class Tags {
    //自增列
    @PrimaryGeneratedColumn()
    id: number
    //普通列
    @Column()
    name: string

    // 多对多关系,通过中间表book_tags关联
    @ManyToMany(() => Book, book => book.tags)
    @JoinTable({
        name: 'book_tags',
        joinColumn: {
            name: 'tag_id',
            referencedColumnName: 'id'
        },
        inverseJoinColumn: {
            name: 'book_id',
            referencedColumnName: 'id'

        }
    })
    books: Book[]
}